package zhuzx.solution;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Random;

public class AllotManhour {
	
	public static void main(String[] args) {
		allot(167, 131);
	}

	public static void allot(double total, int num) {
		double[] array = new double[num];
		Arrays.fill(array, 1.0);
		BigDecimal waitingAllot = new BigDecimal(String.valueOf(total)).subtract(new BigDecimal(num));
		Random r = new Random();
		double[] factorArray = {0.5, 0.5, 1.0};
		for (; waitingAllot.compareTo(BigDecimal.ZERO) > 0;) {
			int index = r.nextInt(array.length);
			BigDecimal incr = new BigDecimal(String.valueOf(
					factorArray[r.nextInt(factorArray.length)]
			));
			if (waitingAllot.compareTo(incr) < 0) {
				incr = waitingAllot;
			}
			BigDecimal newValue = new BigDecimal(String.valueOf(array[index])).add(incr);
			array[index] = newValue.doubleValue();
			waitingAllot = waitingAllot.subtract(incr);
		}
		for (double d : array) {
			System.out.println(d);
		}
	}
	
}